<?php

  function _writeFile($writeFileHandle, $writeContent){
    $writeContent_modified = strval($writeContent) . "\n";
    fwrite($writeFileHandle, $writeContent_modified);
  }

  function _pageFile_read($fileHandle, $filePath){
    $lineNum = 0;
    while(($line = fgets($fileHandle)) != false){
      printf("extracted line %d:\n%s", $lineNum, $line);
      //_writeFile($writeFile_handle, $line);
      $lineNum++;
    }
  }

  function main(){
    $url = "data";
    $recordFilePath = "record.txt";
    /**
    $writeFile_handle = fopen($recordFilePath, b);
    if($writeFile_handle == false){
      echo "open or create file for writting failed!";
    }
    **/
    $readFile_handle = fopen($url, r);
    if($readFile_handle){
      echo "open file success!\n";
      _pageFile_read($readFile_handle, $url);
      echo "read file success!\n";
    }else{
      echo "file open error!";
    }
  }main();
 ?>
